<?php

require_once('../includes/SmartyManager.class.php');
require_once('../includes/DB.class.php');
require_once('../includes/exceptions/AppExceptions.class.php');
require_once('../includes/functions.inc.php');


$fn = $_POST['filename'];
$ut = $_POST['uploadTime'];
$table = 'little_'.$_POST['type'];

$smarty = SmartyManager::getSmarty();

beginTransaction();
if($_POST['type']=='chuku'){
	$table .='_file'; 
	$query = "select id from $table where uploadTime = '$ut' and filename = '$fn'";
	$result = DB::query($query);
	$row = $result->fetch_assoc();
	$query1 = "delete from little_chuku where fileId = {$row['id']}";
	$query2 = "delete from $table where uploadTime = '$ut' and filename = '$fn'";
	try{
		LogInserter::logForDelete("删除文件名中所有信息，文件名：$fn");
		DB::query($query1);
		DB::query($query2);
		commit();
	}catch(Exception $e){
		$smarty->assign('errMsg', $e);
		$smarty->assign('errTitle', '删除时发现数据库错误');
		$smarty->display('error.html');
		rollback();
		die();
	}
}else{
	$query = "delete from $table where uploadTime = '$ut' and filename = '$fn'";
	try{
		LogInserter::logForDelete("删除文件名中所有信息，文件名：$fn");
		DB::query($query);
		commit();
	}catch(Exception $e){
		$smarty->assign('errMsg', $e);
		$smarty->assign('errTitle', '删除时发现数据库错误');
		$smarty->display('error.html');
		rollback();
		die();
	}
}

$smarty->assign('successTitle', '删除文件成功');
$smarty->assign('successMsg','');
$smarty->display('success.html');
?>